#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<errno.h>
#include<fcntl.h>
#include<unistd.h> 
#include<pthread.h>

int
main(void)
{
	int flags = fcntl(STDIN_FILENO,	F_GETFL);
	if(flags < 0){
		perror("get stdin FL faild");
		exit(1);
	}
	flags |= O_NONBLOCK;
	if(fcntl(STDIN_FILENO, F_SETFL, flags) < 0){
		perror("set stdin FL faild");
		exit(1);
	}

	int n = 0;
	char buffer[1024];
	int i = 0;
	for(; i < 5; i ++)
	{
		n = read(STDIN_FILENO, buffer, 10);
		if(n < 0 && errno == EAGAIN){
			printf("please write in terminal\n");
			sleep(3);
			continue;
		}
		else if(n < 0){
			perror("read failed");
			exit(0);
		}
		else break;
	}
	if(i == 5)	perror("terminal empty\n");
	else write(STDOUT_FILENO, buffer, n);
		
	return 0;
}